import { RouteRecordRaw } from 'vue-router';

import { AppRouteRecordRaw } from '@/types/route';

const rootRoute: AppRouteRecordRaw = {
  path: '/',
  redirect: '/app',
  name: 'root',
  meta: {
    title: 'Root',
  },
};

const staticRoutes: AppRouteRecordRaw[] = [
  {
    path: '/login',
    meta: {
      title: 'login.page.title',
    },
    component: () => import('@/views/account/login.vue'),
  },
];

// 引入模块的default 导出
const modules = import.meta.glob('./modules/**/*.ts', {
  eager: true,
  import: 'default',
});
// 引入模块路由
const moduleRoutes = values(modules).flatMap((module: any) => {
  return isArray(module) ? [...module] : [module];
});

const routes: RouteRecordRaw[] = [rootRoute, ...moduleRoutes, ...staticRoutes];

export default routes;
